const _ = require('lodash');

module.exports = {
  schedule: {
    cron: '30 0,30 6-23 * * ?',
    type: 'worker',
    env: ['pachong'],
    // immediate: true
  },

  async task(ctx) {
    // 技术版块
    const r1 = await ctx.service.crawlerSvc.wuyaoctoAll();
    // const r2 = await ctx.service.crawlerSvc.kaifazhetoutiao();
    const r3 = await ctx.service.crawlerSvc.infoqAll();
    const r4 = await ctx.service.crawlerSvc.oschinaAll();
    // const r5 = await ctx.service.crawlerSvc.juejinAll();
    // const r6 = await ctx.service.crawlerSvc.testerhome();


    const r7 = await ctx.service.crawlerSvc.shaoshupai();
    const r8 = await ctx.service.crawlerSvc.liangziwei();
    // const r10 = await ctx.service.crawlerSvc.longtengwang();
    const r12 = await ctx.service.crawlerSvc.bohaishibei();
    const r13 = await ctx.service.crawlerSvc.guokrAll();
    const r14 = await ctx.service.crawlerSvc.jiandan();
    const r15 = await ctx.service.crawlerSvc.zhihuDaily();
    const r16 = await ctx.service.crawlerSvc.idaily();
    const r17 = await ctx.service.crawlerSvc.qunar();
    const r18 = await ctx.service.crawlerSvc.tongcheng();
    const r19 = await ctx.service.crawlerSvc.tuniu();
    const r20 = await ctx.service.crawlerSvc.mafengwo();


    // const r21 = await ctx.service.commonSvc.commonZhihu('陈翔六点半', 'yutang');
    // r21.forEach(v => {
    //   v.boards = ['搞笑'];
    // })
    const r22 = await ctx.service.crawlerSvc.huxiuAll();
    const r24 = await ctx.service.crawlerSvc.meirixiache();
    const r25 = await ctx.service.crawlerSvc.dbaplus();
    const r26 = await ctx.service.crawlerSvc.meituanjishu();
    // const r27 = await ctx.service.crawlerSvc.lengdanxiong();


    // const r30 = await ctx.service.crawlerSvc.wangyiAll();
    // const r31 = await ctx.service.crawlerSvc.sohuAll();

    const topics = r1
      // .concat(r2)
      .concat(r3)
      .concat(r4)
      .concat(r7)
      .concat(r8)
      // .concat(r10)
      .concat(r12)
      .concat(r13)
      .concat(r14)
      .concat(r15)
      .concat(r16)
      .concat(r17)
      .concat(r18)
      .concat(r19)
      .concat(r20)
      // .concat(r21)
      .concat(r22)
      .concat(r24)
      .concat(r25)
      .concat(r26)
    ;

    const shuffle_topics = _.shuffle(topics);

    const result = await ctx.service.topicSvc.importTopics(shuffle_topics);
    ctx.logger.info(`hour ready ${topics.length} success ${result}`);
  }
};
